package org.yn.base.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.yn.auth.domain.Role;
import org.yn.auth.mapper.RoleMapper;
import org.yn.base.mapper.IBaseMapper;
import org.yn.base.query.BaseQuery;
import org.yn.base.service.IBaseService;
import org.yn.base.util.PageInfo;
import org.yn.query.RoleQuery;

import java.util.List;
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    IBaseMapper<T> mapper;

    @Transactional
    public void update(T role) {
        mapper.update(role);
    }

    @Transactional
    public void insert(T role) {
        mapper.insert(role);
    }


    public List<T> selectAll() {
        return mapper.selectAll();
    }


    public T selectById(Long id) {
        return (T) mapper.selectById(id);
    }

    @Transactional
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Transactional
    public void batchDelete(List<Long> ids) {
        mapper.batchDelete(ids);
    }


    public PageInfo<T> queryPage(BaseQuery query) {
        Integer total =mapper.countTotal(query);
        if (total==0){
            return new PageInfo<T>();//返回一个空的
        }
        //查询分页数据
        List<T> list= mapper.queryPage(query);

        return new PageInfo<T>(total, list);
    }



}
